#ifndef __IMX347_CMOS_PARAM_H_
#define __IMX347_CMOS_PARAM_H_

#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif

#include <linux/cvi_vip_cif.h>
#include <linux/cvi_vip_snsr.h>
#include "cvi_type.h"
#include "cvi_sns_ctrl.h"
#include "imx347_cmos_ex.h"

static const IMX347_MODE_S g_astImx347_mode[IMX347_MODE_NUM] = {
	[IMX347_MODE_4M60] = {
		.name = "4M60",
		.astImg[0] = {
			.stSnsSize = {
				.u32Width = 2712,
				.u32Height = 1538,
			},
			.stWndRect = {
				.s32X = 12,
				.s32Y = 10,
				.u32Width = 2688,
				.u32Height = 1520,
			},
			.stMaxSize = {
				.u32Width = 2712,
				.u32Height = 1538,
			},
		},
		.f32MaxFps = 60,
		.f32MinFps = 0.1, /* 0x672 * 60 / 0xFFFFF */
		.u32HtsDef = 0x2EE, //hmax
		.u32VtsDef = 0x672, //vmax=1650
		.stExp[0] = {
			.u16Min = 1,
			.u16Max = 0x672 - 3,
			.u16Def = 192,
			.u16Step = 1,
		},
		.stAgain[0] = {
			.u32Min = 1024,
			.u32Max = 76789,	// HCG
			//.u32Max = 30220,	// no HCG
			.u32Def = 1024,
			.u32Step = 1,
		},
		.stDgain[0] = {
			.u32Min = 1024,
			.u32Max = 128913,
			.u32Def = 1024,
			.u32Step = 1,
		},
	},
	[IMX347_MODE_4M30_WDR] = {
		.name = "4M60wdr",
		/* sef */
		.astImg[0] = {
			.stSnsSize = {
				.u32Width = 2712,
				.u32Height = 1538,
			},
			.stWndRect = {
				.s32X = 12,
				.s32Y = 10,
				.u32Width = 2688,
				.u32Height = 1520,
			},
			.stMaxSize = {
				.u32Width = 2712,
				.u32Height = 1538,
			},
		},
		/* lef */
		.astImg[1] = {
			.stSnsSize = {
				.u32Width = 2712,
				.u32Height = 1538,
			},
			.stWndRect = {
				.s32X = 12,
				.s32Y = 10,
				.u32Width = 2688,
				.u32Height = 1520,
			},
			.stMaxSize = {
				.u32Width = 2712,
				.u32Height = 1538,
			},
		},
		.f32MaxFps = 30,
		.f32MinFps = 0.05, /* 0x672 * 30 / 0xFFFFF */
		.u32HtsDef = 0x2EE, //hmax
		.u32VtsDef = 0x672, //vmax=1650
		.stExp[0] = {
			.u16Min = 11,
			.u16Max = 181, // within FSC: RHS1 < 2*(VMAX-BRL-2)+3
			.u16Def = 21,  // 4n + 1
			.u16Step = 4,
		},
		.stExp[1] = {
			.u16Min = 2,
			.u16Max = 0x672 * 2 - 20,
			.u16Def = 512,
			.u16Step = 2,
		},
		.stAgain[0] = {
			.u32Min = 1024,
			.u32Max = 30220,
			.u32Def = 1024,
			.u32Step = 1,
		},
		.stAgain[1] = {
			.u32Min = 1024,
			.u32Max = 30220,
			.u32Def = 1024,
			.u32Step = 1,
		},
		.stDgain[0] = {
			.u32Min = 1024,
			.u32Max = 128913,
			.u32Def = 1024,
			.u32Step = 1,
		},
		.stDgain[1] = {
			.u32Min = 1024,
			.u32Max = 128913,
			.u32Def = 1024,
			.u32Step = 1,
		},
		// .u16RHS1 = 0x15,
		.u16BRL = 1538 + 20,
		.u16OpbSize = 0x13,
		// .u16MarginVtop = (0x15 - 3) / 2,
		// .u16MarginVbot = (0x15 - 3) / 2 + 1,
	},
};

static ISP_CMOS_NOISE_CALIBRATION_S g_stIspNoiseCalibratio = {.CalibrationCoef = {
	{	//iso  100
		{0.02189878374338150024,	3.87094926834106445313}, //B: slope, intercept
		{0.01703374087810516357,	5.44619417190551757813}, //Gb: slope, intercept
		{0.01661862060427665710,	5.48960638046264648438}, //Gr: slope, intercept
		{0.01759656332433223724,	4.97358703613281250000}, //R: slope, intercept
	},
	{	//iso  200
		{0.02798131853342056274,	5.56187105178833007813}, //B: slope, intercept
		{0.01981561444699764252,	8.49956417083740234375}, //Gb: slope, intercept
		{0.02011663652956485748,	8.25231838226318359375}, //Gr: slope, intercept
		{0.02186746336519718170,	7.31797695159912109375}, //R: slope, intercept
	},
	{	//iso  400
		{0.03867063671350479126,	7.87299871444702148438}, //B: slope, intercept
		{0.02545141056180000305,	12.52388763427734375000}, //Gb: slope, intercept
		{0.02501225471496582031,	12.50799369812011718750}, //Gr: slope, intercept
		{0.02971377409994602203,	10.59786605834960937500}, //R: slope, intercept
	},
	{	//iso  800
		{0.05254572257399559021,	11.33435535430908203125}, //B: slope, intercept
		{0.03459533303976058960,	17.70245933532714843750}, //Gb: slope, intercept
		{0.03523396328091621399,	17.42684555053710937500}, //Gr: slope, intercept
		{0.04034899175167083740,	15.29961872100830078125}, //R: slope, intercept
	},
	{	//iso  1600
		{0.07306019961833953857,	16.53976440429687500000}, //B: slope, intercept
		{0.05263451859354972839,	23.31527519226074218750}, //Gb: slope, intercept
		{0.05249603465199470520,	23.05733299255371093750}, //Gr: slope, intercept
		{0.06904666870832443237,	17.36592483520507812500}, //R: slope, intercept
	},
	{	//iso  3200
		{0.10001315921545028687,	24.69992637634277343750}, //B: slope, intercept
		{0.07434318214654922485,	32.97191619873046875000}, //Gb: slope, intercept
		{0.07484170049428939819,	31.96492958068847656250}, //Gr: slope, intercept
		{0.09528645873069763184,	25.67140579223632812500}, //R: slope, intercept
	},
	{	//iso  6400
		{0.13351915776729583740,	36.17586135864257812500}, //B: slope, intercept
		{0.09981396794319152832,	47.61682510375976562500}, //Gb: slope, intercept
		{0.10151956975460052490,	46.98117446899414062500}, //Gr: slope, intercept
		{0.13463120162487030029,	36.68984603881835937500}, //R: slope, intercept
	},
	{	//iso  12800
		{0.21647229790687561035,	45.42202377319335937500}, //B: slope, intercept
		{0.14789910614490509033,	65.45682525634765625000}, //Gb: slope, intercept
		{0.14988273382186889648,	64.35728454589843750000}, //Gr: slope, intercept
		{0.20631974935531616211,	48.98140335083007812500}, //R: slope, intercept
	},
	{	//iso  25600
		{0.29134646058082580566,	70.35582733154296875000}, //B: slope, intercept
		{0.20431476831436157227,	99.39897155761718750000}, //Gb: slope, intercept
		{0.20107901096343994141,	97.40054321289062500000}, //Gr: slope, intercept
		{0.26320499181747436523,	77.81734466552734375000}, //R: slope, intercept
	},
	{	//iso  51200
		{0.34115397930145263672,	123.63335418701171875000}, //B: slope, intercept
		{0.21777287125587463379,	186.51731872558593750000}, //Gb: slope, intercept
		{0.21872699260711669922,	181.58232116699218750000}, //Gr: slope, intercept
		{0.28329473733901977539,	145.61508178710937500000}, //R: slope, intercept
	},
	{	//iso  102400
		{0.49404108524322509766,	172.70755004882812500000}, //B: slope, intercept
		{0.29687431454658508301,	266.28817749023437500000}, //Gb: slope, intercept
		{0.30924040079116821289,	253.35063171386718750000}, //Gr: slope, intercept
		{0.41298082470893859863,	208.26261901855468750000}, //R: slope, intercept
	},
	{	//iso  204800
		{0.65840476751327514648,	232.06245422363281250000}, //B: slope, intercept
		{0.39821600914001464844,	387.80480957031250000000}, //Gb: slope, intercept
		{0.39707985520362854004,	387.03244018554687500000}, //Gr: slope, intercept
		{0.56851047277450561523,	273.35931396484375000000}, //R: slope, intercept
	},
	{	//iso  409600
		{0.72311550378799438477,	412.08703613281250000000}, //B: slope, intercept
		{0.42630678415298461914,	610.66595458984375000000}, //Gb: slope, intercept
		{0.42771303653717041016,	610.94873046875000000000}, //Gr: slope, intercept
		{0.58606457710266113281,	488.73452758789062500000}, //R: slope, intercept
	},
	{	//iso  819200
		{0.72311550378799438477,	412.08703613281250000000}, //B: slope, intercept
		{0.42630678415298461914,	610.66595458984375000000}, //Gb: slope, intercept
		{0.42771303653717041016,	610.94873046875000000000}, //Gr: slope, intercept
		{0.58606457710266113281,	488.73452758789062500000}, //R: slope, intercept
	},
	{	//iso  1638400
		{0.72311550378799438477,	412.08703613281250000000}, //B: slope, intercept
		{0.42630678415298461914,	610.66595458984375000000}, //Gb: slope, intercept
		{0.42771303653717041016,	610.94873046875000000000}, //Gr: slope, intercept
		{0.58606457710266113281,	488.73452758789062500000}, //R: slope, intercept
	},
	{	//iso  3276800
		{0.72311550378799438477,	412.08703613281250000000}, //B: slope, intercept
		{0.42630678415298461914,	610.66595458984375000000}, //Gb: slope, intercept
		{0.42771303653717041016,	610.94873046875000000000}, //Gr: slope, intercept
		{0.58606457710266113281,	488.73452758789062500000}, //R: slope, intercept
	},
} };

static ISP_CMOS_BLACK_LEVEL_S g_stIspBlcCalibratio = {
	.bUpdate = CVI_TRUE,
	.blcAttr = {
		.Enable = 1,
		.enOpType = OP_TYPE_AUTO,
		.stManual = {200, 200, 200, 200, 1076, 1076, 1076, 1076},
		.stAuto = {
			{200, 200, 200, 201, 201, 202, 203, 210, /*8*/215, 236, 268, 312, 1321, 3934, 4053, 4052},
			{200, 200, 200, 201, 201, 202, 203, 210, /*8*/214, 235, 266, 309, 1314, 3933, 4052, 4051},
			{200, 200, 200, 201, 201, 202, 203, 210, /*8*/215, 237, 267, 312, 1317, 3939, 4053, 4053},
			{200, 200, 200, 201, 201, 202, 203, 210, /*8*/215, 236, 266, 309, 1310, 3936, 4051, 4052},
			{1077, 1077, 1077, 1077, 1077, 1077, 1077, 1079,
				/*8*/1081, 1087, 1096, 1108, 1512, 26045, 65535, 65535},
			{1077, 1077, 1077, 1077, 1077, 1077, 1077, 1079,
				/*8*/1080, 1086, 1095, 1108, 1508, 25884, 65535, 65535},
			{1077, 1077, 1077, 1077, 1077, 1077, 1077, 1079,
				/*8*/1081, 1087, 1095, 1108, 1509, 26880, 65535, 65535},
			{1077, 1077, 1077, 1077, 1077, 1077, 1077, 1079,
				/*8*/1081, 1087, 1095, 1108, 1506, 26373, 65535, 65535},
		},
	},
};

struct combo_dev_attr_s imx347_rx_attr = {
	.input_mode = INPUT_MODE_MIPI,
	.mac_clk = RX_MAC_CLK_400M,
	.mipi_attr = {
		.raw_data_type = RAW_DATA_12BIT,
		.lane_id = {4, 0, 1, 2, 3}, // for 3SVision
		.pn_swap = {0, 0, 0, 0, 0},
		.wdr_mode = CVI_MIPI_WDR_MODE_VC,
	},
	.mclk = {
		.cam = 0,
		.freq = CAMPLL_FREQ_37P125M,
	},
	.devno = 0,
};

#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* End of #ifdef __cplusplus */

#endif /* __IMX347_CMOS_PARAM_H_ */
